<?php
/**
 * Created by PhpStorm.
 * User: 王泽锋
 * Date: 2018/03/09
 * Time: 11:26
 */

namespace app\home\model;


use think\Model;
use think\Db;
class Shopping_cart extends Model
{
    //首页获取的数据
    public function get_list($where, $length = 0)
    {
        $list = $this->where($where)->order('create_time', 'desc')->limit($length, 12)->select();
        foreach ($list as $key => $value) {
            $rs = Db::table('pb_shopping_commodity')->where('id', $value['cid'])->find();
            $value['front_cover'] = get_covers($rs['front_cover']);
            $value['title'] = $rs['title'];
            $value['price'] = number_format($rs['price'], 2, ".", "");
            $value['price1'] = floor($value['price']);
            $value['price2'] = mb_substr($value['price'], -2);
            $value['stock'] = $rs['stock'];

        }
        return $list;
    }

    /*
     * 上拉加载
     * */
    public function get_lists($where, $length = 0)
    {
        $list = $this->where($where)->order('create_time', 'desc')->limit($length, 6)->select();
        foreach ($list as $key => $value) {
            $rs = Db::table('pb_shopping_commodity')->where('id', $value['cid'])->find();
            $value['front_cover'] = get_covers($rs['front_cover']);
            $value['title'] = $rs['title'];
            $value['price'] = number_format($rs['price'], 2, ".", "");
            $value['price1'] = floor($value['price']);
            $value['price2'] = mb_substr($value['price'], -2);
            $value['stock'] = $rs['stock'];

        }
        return $list;
    }

}